﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfZMotion_DHAgeingOven.Core.IO
{
    public class IODictionary<TKey, TValue> : Dictionary<TKey, TValue> where TKey : class, IComparable<String>
    {
        public TValue this[Enum @enum]
        {
            get
            {
                if (@enum.ToString() is TKey key)
                {
                    if (this.ContainsKey(key))
                    {
                        return this[key];
                    }
                    else
                    {
                        throw new ArgumentException($"键名不存在:{@enum}", nameof(@enum));
                    }
                }
                else
                {
                    throw new InvalidCastException($"键名无法转换:{@enum}");
                }

            }
            set
            {
                if (@enum.ToString() is TKey key)
                {
                    if (this.ContainsKey(key))
                    {
                        this[key] = value;
                    }
                    else
                    {
                        throw new ArgumentException($"键名不存在:{@enum}", nameof(@enum));
                    }
                }
                else
                {
                    throw new InvalidCastException($"键名无法转换:{@enum}");
                }
            }
        }

    }
}
